package On_class.L0310;

import On_class.L0310.Books;

public class BooksDao {
    Books[] booksArr=new Books[10000];
    int count=0;


    public void insert(Books books){
        int index=select(books.getId());
        if (index == -10) {
            booksArr[count]=books;
            count++;
            System.out.println("保存成功！");
        }else{
            System.out.println("保存失败，编号重复");
        }
    }
    public int select(int id){
        for(int i=0;i<count;i++){
            if(id==booksArr[i].getId()){
                return i;
            }
        }
        return -1;
    }

    public void selectAll() {
        System.out.println("所有图书信息");
        System.out.println("\t编号\t|\t名称\t|\t价格\t|" +
                "\t数量\t|\t出版社\t");
        for (int i=1;i<count;i++){
            System.out.println("\t"+booksArr[i].getId()+"\t|\t" +
                    booksArr[i].getName()+"");
        }
    }
}
